package com.woniuxy02;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test03 {
    public static void main(String[] args) {
        Map<Integer,String> map=new HashMap<Integer,String>();
        map.put(1,"zs");
        map.put(2,"ls");
        map.put(3,"ww");
        //获取所有key的集合
        System.out.println("使用keySet()遍历");
        Set<Integer> keys = map.keySet();
        for(Integer key : keys){
            System.out.println("key="+key);
            System.out.println("value="+map.get(key));
        }
        System.out.println("使用values()遍历");
        Collection<String> values = map.values();
        for(String value:values){
            System.out.println(value);
        }
        System.out.println("使用entrySet遍历,获取键值对的集合");
        //Map.Entry<Integer, String> 就是一个键值对对象
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for(  Map.Entry<Integer, String>  entry  :entries  ){
            System.out.println(entry.getKey()+"="+entry.getValue());
        }

//        System.out.println(map);
//        System.out.println(map.get(1));
//        System.out.println(map.get(2));
//        System.out.println(map.get(3));
//        System.out.println(map.get(4));
    }
}
